import {useRouter, useRoute} from "vue-router";

export function initRouterUtil() {

  const router = useRouter();
  const route = useRoute();


  /**
   * 封装重定向
   */
  const replace = (path, redirectUrl = null) => {
    if (redirectUrl) {
      return router.push({
        path: path,
        query: {
          redirectUrl: redirectUrl
        }
      })
    } else {
      return router.replace(path);
    }
  }

  const getParams = () => {
    return {
      ...route.params
    }
  }

  return {
    replace,
    getParams
  }

}